using System;

namespace ZLWeb.WebApiConfigration.WebapiAppsetting
{
    [Serializable]
    public class ZLWebApiAppSetting
    {
        private static ZLWebApiAppSetting appSetting;
        //public ZLWebApiAppSetting();
        private ZLWebApiAppSetting()
        {
        }

        public string RunLogLevel { get; set; }
        public string SelfHostUrl { get; set; }
        public static ZLWebApiAppSetting GetAppSetting()
        {
            if (appSetting == null)
                appSetting = new ZLWebApiAppSetting();
            return appSetting;
        }

        public void LoadData(string file)
        {
            ConfigrationUtil.SetZlWebConfigPath(file);

            foreach (var info in typeof (ZLWebApiAppSetting).GetProperties())
            {
                try
                {
                    var configvalue = ConfigrationUtil.ReadConfig(info.Name);
                    appSetting.GetType().GetProperty(info.Name).SetValue(appSetting, configvalue,null);
                   
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
    }
}